package com.lx.controller;

import com.lx.service.IMailService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 邮件发送
 *
 * @author 段誉
 * @create 2019-04-08 20:06
 */
@RequestMapping("/mail")
@RestController
public class EmailController {
  @Autowired
  private IMailService mailService;

  @GetMapping("/simple")
  public Map<String, Object> sendSimpleMail() {
    Map<String, Object> map = new HashMap<>();
    try {
      mailService.simpleMil("******@163.com");
      map.put("res", "success");
    } catch (Exception e) {
      e.printStackTrace();
      map.put("res", "error");
    }
    return map;
  }

  @GetMapping("/html")
  public Map<String, Object> htmlMail(){
    Map<String, Object> map =new HashMap<>();
    try {
      mailService.htmlMail("******@163.com");
      map.put("res", "success");
    } catch (Exception e) {
      e.printStackTrace();
      map.put("res", "error");
    }
    return map;
  }

  @GetMapping("/attachments")
  public Map<String, Object> attachmentsMail(){
    Map<String, Object> map =new HashMap<>();
    try {
      mailService.attachmentMail("******@163.com");
      map.put("res", "success");
    } catch (Exception e) {
      e.printStackTrace();
      map.put("res", "error");
    }
    return map;
  }

  @GetMapping("/img")
  public Map<String, Object> imgMail(){
    Map<String, Object> map =new HashMap<>();
    try {
      mailService.imgMail("******@163.com");
      map.put("res", "success");
    } catch (Exception e) {
      e.printStackTrace();
      map.put("res", "error");
    }
    return map;
  }

  @GetMapping("/template")
  public Map<String, Object> templateMail(){
    Map<String, Object> map =new HashMap<>();
    try {
      mailService.templateMail("******@163.com");
      map.put("res", "success");
    } catch (Exception e) {
      e.printStackTrace();
      map.put("res", "error");
    }
    return map;
  }
}
